package com.xposed.aliproxy.xposed;

import android.content.Context;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.TextView.BufferType;

import com.xposed.aliproxy.xlistener.XposedAttachedListener;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodHook.MethodHookParam;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;

public class AliHookMethod extends XC_MethodHook {
    private AliHookMethodb hookMethodb;
    private AliHookMethodc hookMethodc;
    private AliHookMethodd hookMethodd;
    private AliHookMethode hookMethode;
    private AliHookMethodf hookMethodf;
    private AliHookMethodg hookMethodg;
    private XposedAttachedListener listener;
    private LoadPackageParam loadPackageParam;
    private String pkgName;
    private String processName;
    private AliReplaceMethodh replaceMethodh;
    private AliReplaceMethodj replaceMethodj;
    private Tutorial tutorial;

    public AliHookMethod(XposedAttachedListener xposedAttachedListener, Tutorial tutorial, LoadPackageParam loadPackageParam, String str, String str2) {
        this.listener = xposedAttachedListener;
        this.tutorial = tutorial;
        this.pkgName = str;
        this.processName = str2;
        this.loadPackageParam = loadPackageParam;
    }

    @Override
    protected void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable {
        super.afterHookedMethod(methodHookParam);
        if (this.processName.equals("com.eg.android.AlipayGphone") && !this.tutorial.aliHooked) {
            this.tutorial.aliHooked = true;
            if (this.loadPackageParam.appInfo != null && (this.loadPackageParam.appInfo.flags & 129) == 0) {
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.addAction("com.abcd.action.xposedaction.generateqrcode");
                intentFilter.addAction("com.abcd.action.xposedaction.unregister");
                Context context = (Context) methodHookParam.args[0];
                context.registerReceiver(this.tutorial.broadcastReceiver, intentFilter);
                ClassLoader classLoader = context.getClassLoader();
                try {
                    Class findClass = XposedHelpers.findClass("com.alipay.mobile.base.security.CI", classLoader);
                    XposedHelpers.findAndHookMethod(TextView.class, "setText", CharSequence.class, BufferType.class, Boolean.TYPE, Integer.TYPE, new AliBalanceHookMethod(context));
                    if (this.hookMethodg == null) {
                        this.hookMethodg = new AliHookMethodg();
                    }
                    XposedHelpers.findAndHookMethod(findClass, "a", String.class, String.class, String.class, this.hookMethodg);
                    if (this.replaceMethodh == null) {
                        this.replaceMethodh = new AliReplaceMethodh();
                    }
                    XposedHelpers.findAndHookMethod(findClass, "a", Class.class, String.class, String.class, this.replaceMethodh);
                    if (this.replaceMethodj == null) {
                        this.replaceMethodj = new AliReplaceMethodj();
                    }
                    XposedHelpers.findAndHookMethod(findClass, "a", Class.class, String.class, String.class, this.replaceMethodj);
                    findClass = XposedHelpers.findClass("com.alipay.android.phone.messageboxstatic.biz.dao.TradeDao", classLoader);
                    if (this.hookMethodb == null) {
                        this.hookMethodb = new AliHookMethodb(context, classLoader);
                    }
                    XposedBridge.hookAllMethods(findClass, "insertMessageInfo", this.hookMethodb);
                    findClass = XposedHelpers.findClass("com.alipay.android.phone.messageboxstatic.biz.dao.ServiceDao", classLoader);
                    if (this.hookMethodc == null) {
                        this.hookMethodc = new AliHookMethodc(context, classLoader);
                    }
                    XposedBridge.hookAllMethods(findClass, "insertMessageInfo", this.hookMethodc);
                    String str = "com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity";
                    if (this.hookMethodd == null) {
                        this.hookMethodd = new AliHookMethodd();
                    }
                    XposedHelpers.findAndHookMethod(str, classLoader, "onCreate", Bundle.class, this.hookMethodd);
                    findClass = XposedHelpers.findClass("com.alipay.transferprod.rpc.result.ConsultSetAmountRes", classLoader);
                    String str2 = "com.alipay.mobile.payee.ui.PayeeQRSetMoneyActivity";
                    if (this.hookMethode == null) {
                        this.hookMethode = new AliHookMethode(context);
                    }
                    XposedHelpers.findAndHookMethod(str2, classLoader, "a", findClass, this.hookMethode);
                    str = "com.alipay.mobile.quinox.LauncherActivity";
                    if (this.hookMethodf == null) {
                        this.hookMethodf = new AliHookMethodf(context, classLoader);
                    }
                    if (context.getPackageManager().getPackageInfo("com.eg.android.AlipayGphone", 0).versionName.startsWith("10.1.35")) {
                        XposedHelpers.findAndHookMethod(str, classLoader, "onResume", Boolean.TYPE, this.hookMethodf);
                    } else {
                        XposedHelpers.findAndHookMethod(str, classLoader, "onResume", this.hookMethodf);
                    }
                    this.listener.onComplete();
                } catch (Throwable th) {
                    this.listener.onComplete();
                }
            }
        }
    }
}
